home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * img_seek, img_write, img_read, img_optseek -
- *
- * Paul Haeberli - 1984
- *
- */
- #include <stdio.h>
- #include "image.h"
-
- img_seek(image, y, z)
- IMAGE *image;
- unsigned int y, z;
- {
- if(img_badrow(image,y,z)) {
- i_errhdlr("img_seek: row number out of range\n");
- return EOF;
- }
- image->x = 0;
- image->y = y;
- image->z = z;
- if(ISVERBATIM(image->type)) {
- switch(image->dim) {
- case 1:
- return img_optseek(image, 512L);
- case 2:
- return img_optseek(image,512L+(y*image->xsize)*BPP(image->type));
- case 3:
- return img_optseek(image,
- 512L+(y*image->xsize+z*image->xsize*image->ysize)*
- BPP(image->type));
- default:
- i_errhdlr("img_seek: weird dim\n");
- break;
- }
- } else if(ISRLE(image->type)) {
- switch(image->dim) {
- case 1:
- return img_optseek(image, image->rowstart[0]);
- case 2:
- return img_optseek(image, image->rowstart[y]);
- case 3:
- return img_optseek(image, image->rowstart[y+z*image->ysize]);
- default:
- i_errhdlr("img_seek: weird dim\n");
- break;
- }
- } else
- i_errhdlr("img_seek: weird image type\n");
- }
-
- img_badrow(image,y,z)
- IMAGE *image;
- int y, z;
- {
- if(y>=image->ysize || z>=image->zsize)
- return 1;
- else
- return 0;
- }
-
- img_write(image,buffer,count)
- IMAGE *image;
- char *buffer;
- long count;
- {
- long retval;
-
- retval = write(image->file,buffer,count);
- if(retval == count)
- image->offset += count;
- else
- image->offset = -1;
- return retval;
- }
-
- img_read(image,buffer,count)
- IMAGE *image;
- char *buffer;
- long count;
- {
- long retval;
-
- retval = read(image->file,buffer,count);
- if(retval == count)
- image->offset += count;
- else
- image->offset = -1;
- return retval;
- }
-
- img_optseek(image,offset)
- IMAGE *image;
- unsigned long offset;
- {
- if(image->offset != offset) {
- image->offset = offset;
- return lseek(image->file,offset,0);
- }
- return offset;
- }
-
-